import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Location } from '@angular/common';

import { CategoryService } from '../../../services/category.service';
import { aroAnimation } from '../../../animation';

@Component({
  selector: 'app-category-main',
  templateUrl: './category-main.component.html',
  styleUrls: ['./category-main.component.css'],
  animations: [aroAnimation]
})
export class CategoryMainComponent implements OnInit {

  public categories: Array<any> = JSON.parse(localStorage.getItem('BookCategory')) || [];
  // public tempCategories: Array<any> = [];

  constructor(private categoryService: CategoryService, private location: Location, private currentRouter: ActivatedRoute,
    private router: Router) { }

  ngOnInit() {
    this.categoryService.getList().subscribe(res => {
      // console.log(res);
      if (res.Code == 100) {
        this.categories = res.Data;
        localStorage.setItem('BookCategory', JSON.stringify(this.categories));
      }
    });
  }

  public goList(category) {
    this.router.navigate(['./booklist/', category.Id, category.Name]);
  }

}
